package com.binfast.app.admin.controller;

import cn.hutool.log.Log;
import cn.hutool.log.LogFactory;
import com.binfast.app.admin.services.AdminUserServ;
import com.binfast.bean.model.auth.AdminUser;
import com.binfast.bean.params.DetailParam;
import com.binfast.bean.params.adminUser.AdminUserDetailSaveParam;
import com.binfast.bean.params.adminUser.AdminUserListParam;
import com.binfast.bean.params.adminUser.AdminUserModifyPasswordParam;
import com.binfast.common.util.Result;
import com.binfast.seed.annotation.LoginUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(value = "/adminUser")
public class AdminUserCtrl {
    private static final Log log = LogFactory.get();

    @Autowired
    AdminUserServ adminUserServ;

    @GetMapping(value = "/findList")
    public Result findList(@Validated AdminUserListParam param) {
        return Result.success(adminUserServ.findList(param));
    }

    @RequestMapping(value = "/findDetail",method = RequestMethod.POST)
    public Result findDetail (@Validated @RequestBody DetailParam param) {
        return Result.success(adminUserServ.findDetail(param));
    }

    @RequestMapping(value = "/saveUser",method = RequestMethod.POST)
    public Result saveOne(@Validated @RequestBody AdminUserDetailSaveParam param) {
        return Result.success(adminUserServ.saveOne(param));
    }


    @RequestMapping(value = "/savePassword",method = RequestMethod.POST)
    public Result savePassword(@Validated @RequestBody AdminUserModifyPasswordParam param, @LoginUser AdminUser adminUser) {
        param.setAdminUser(adminUser);
        return Result.success(adminUserServ.savePassword(param));
    }

    @RequestMapping(value = "/generatePassword",method = RequestMethod.POST)
    public Result generatePassword(@Validated @RequestBody DetailParam param) {
        return Result.success(adminUserServ.generatePassword(param));
    }

    @RequestMapping(value = "/deleteUser",method = RequestMethod.POST)
    public Result deleteOne(@Validated @RequestBody DetailParam param) {
        return Result.success(adminUserServ.deleteOne(param));
    }

    @RequestMapping(value = "/isEnableRole",method = RequestMethod.POST)
    public Result isEnableOne(@Validated @RequestBody DetailParam param) {
        return Result.success(adminUserServ.isEnableOne(param));
    }

}
